package com.util;

import com.generator.entity.Reply;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

/**
 * @Author: htj
 * @Date: 2021/10/4 0004 下午 19:55
 */
@Component
public class Result {

    public Reply getResult(int type, int seqNo, int api_id, int thirdParty_id, String content) {

        //接口开关关闭
        if (type == 1) {
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            Reply reply = new Reply();
            reply.setId(seqNo);//不能正常访问接口的交易，流水号为0
            reply.setThirdpartyId(thirdParty_id);
            reply.setApiId(api_id);
            reply.setStatus(100);
            reply.setMsg("请求失败！该接口暂时关闭，不可访问！");
            reply.setContent("返回报文内容：null");
            reply.setReturnTime(timestamp);
            return reply;
        }

        //超出最大并发数
        if (type == 2) {
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            Reply reply = new Reply();
            reply.setId(seqNo);
            reply.setThirdpartyId(thirdParty_id);
            reply.setApiId(api_id);
            reply.setStatus(200);
            reply.setMsg("请求失败！此刻访问该接口的人数过多，已超出限制，请稍后再尝试访问！");
            reply.setContent("返回报文内容：null");
            reply.setReturnTime(timestamp);
            return reply;
        }

        //没有权限访问该接口
        if (type == 3) {
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            Reply reply = new Reply();
            reply.setId(seqNo);
            reply.setThirdpartyId(thirdParty_id);
            reply.setApiId(api_id);
            reply.setStatus(300);
            reply.setMsg("返回失败，您没有权限访问该接口！");
            reply.setContent("返回报文内容：null");
            reply.setReturnTime(timestamp);
            return reply;
        }

        //网关中没有该接口号
        if (type == 4) {
            Timestamp timestamp = new Timestamp(System.currentTimeMillis());
            Reply reply = new Reply();
            reply.setId(seqNo);
            reply.setThirdpartyId(thirdParty_id);
            reply.setApiId(api_id);
            reply.setStatus(400);
            reply.setMsg("返回失败，没有该接口号！");
            reply.setContent("返回报文内容：null");
            reply.setReturnTime(timestamp);
            return reply;
        }

        //不会执行这句的
        return null;
    }

}
